package com.jn.exam.oss.service.impl;

import com.jn.exam.oss.entity.FaceViolation;
import com.jn.exam.oss.mapper.FaceViolationMapper;
import com.jn.exam.oss.service.FaceViolationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jn.exam.oss.service.OssService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.util.concurrent.Future;

/**
 * <p>
 * 人脸违规记录 服务实现类
 * </p>
 *
 * @author 江南大学1033190417
 * @since 2022-02-19
 */
@Service
public class FaceViolationServiceImpl extends ServiceImpl<FaceViolationMapper, FaceViolation> implements FaceViolationService {

    @Autowired
    private OssService ossService;

    @Override
    @Async
    public Future<Boolean> removeFaceViolationById(String faceViolationId) {
        FaceViolation faceViolation = baseMapper.selectById(faceViolationId);
        String faceUrl = faceViolation.getFaceUrl();
        boolean deleteFile = ossService.deleteFile(faceUrl);//删除oss图片
        int delete = baseMapper.deleteById(faceViolationId);
        if (deleteFile && delete == 1) {
            return new AsyncResult<>(true);
        }
        return new AsyncResult<>(false);
    }
}
